package com.zzyl.serve.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzyl.serve.domain.FamilyMember;
import com.zzyl.serve.domain.FamilyMemberElder;
import com.zzyl.serve.vo.FamilyElderPageVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 老人家属Mapper接口
 * 
 * @author liuyp
 * @date 2025-08-21
 */
@Mapper
public interface FamilyMemberMapper extends BaseMapper<FamilyMember>
{
    /**
     * 查询老人家属
     * 
     * @param id 老人家属主键
     * @return 老人家属
     */
    public FamilyMember selectFamilyMemberById(Long id);

    /**
     * 查询老人家属列表
     * 
     * @param familyMember 老人家属
     * @return 老人家属集合
     */
    public List<FamilyMember> selectFamilyMemberList(FamilyMember familyMember);

    /**
     * 新增老人家属
     * 
     * @param familyMember 老人家属
     * @return 结果
     */
    public int insertFamilyMember(FamilyMember familyMember);

    /**
     * 修改老人家属
     * 
     * @param familyMember 老人家属
     * @return 结果
     */
    public int updateFamilyMember(FamilyMember familyMember);

    /**
     * 删除老人家属
     * 
     * @param id 老人家属主键
     * @return 结果
     */
    public int deleteFamilyMemberById(Long id);

    /**
     * 批量删除老人家属
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFamilyMemberByIds(Long[] ids);


    @Insert("INSERT INTO family_member_elder(family_member_id, elder_id, remark, create_by) VALUES(#{familyMemberId}, #{elderId}, #{remark}, #{createBy})")
    void save(FamilyMemberElder familyMemberElder);


    @Select("SELECT * FROM family_member_elder")
    List<FamilyMemberElder> listAll();

    @Select("SELECT name FROM elder WHERE id = #{elderId}")
    String getElderName(Long elderId);

    @Select("select fe.id mid,fe.elder_id ,fe.remark mremark,e.image,e.name,e.bed_number,r.type_name,d.iot_id,d.device_name,d.product_key " +
            "       from family_member_elder fe " +
            "       left join elder e on fe.elder_id = e.id " +
            "       left join bed b on e.bed_id = b.id " +
            "       left join room r on b.room_id = r.id " +
            "       left join device d on d.binding_location = e.id " +
            "limit #{offset},#{pageSize}")
    List<FamilyElderPageVo> pageQuery(@Param("offset") int offset, @Param("pageSize") int pageSize);
     }
